<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>鼠标边框移动</title>
    <link rel="stylesheet" type="text/css" href="../css/reset.css" />
    <style>
      * {
        box-sizing: border-box;
      }
      .container {
        display: grid;
        grid-template-columns: repeat(4, 1fr);
        gap: 20px;
        width: 90%;
        margin: 10px auto;
        text-align: center;
      }

      .card {
        background-color: rgba(255, 255, 255, 0.1);
        font-size: 25px;
        aspect-ratio: 5 / 3;
        border-radius: 8px;
        position: relative;
        overflow: hidden;
      }
      .card .inner {
        background-color: #222;
        position: absolute;
        inset: 2px;
        display: flex;
        justify-content: center;
        align-items: center;
        color: aliceblue;
        border-radius: inherit;
        z-index: 3;
      }
      .card::before {
        content: "";
        position: absolute;
        z-index: 2;
        inset: 0;
        left: 0;
        top: 0;
        /* background: #fff; */
        /* closest-side circle, */
        background: radial-gradient(
          circle,
          rgba(255, 255, 255, 0.6) 0%,
          transparent
        );
        border-radius: inherit;
        /* transform: translate(0px,0px); */
        transform: translate(var(--x, -1000px), var(--y, -1000px));
      }
      .bottom {
        width: 400px;
        margin: 10px auto;
        background-color: #333;
        opacity: .5;
        padding: 10px;
        border-radius: 5px;
      }
      .bottom-inner {
        width: fit-content;
        color: aliceblue;
        background: gray;
        border-radius: inherit;
      }
    </style>
  </head>
  <body>
    <div class="container">
      <div class="card">
        <div class="inner">hello world!</div>
      </div>
      <div class="card">
        <div class="inner">hello world!</div>
      </div>
      <div class="card">
        <div class="inner">hello world!</div>
      </div>
      <div class="card">
        <div class="inner">hello world!</div>
      </div>
      <div class="card">
        <div class="inner">hello world!</div>
      </div>
      <div class="card">
        <div class="inner">hello world!</div>
      </div>
      <div class="card">
        <div class="inner">hello world!</div>
      </div>
      <div class="card">
        <div class="inner">hello world!</div>
      </div>
      <div class="card">
        <div class="inner">hello world!</div>
      </div>
      <div class="card">
        <div class="inner">hello world!</div>
      </div>
      <div class="card">
        <div class="inner">hello world!</div>
      </div>
      <div class="card">
        <div class="inner">hello world!</div>
      </div>
    </div>
    <div class="bottom">
      <div class="bottom-inner">
        Exclusive copyright for games production! 2024.1
      </div>
    </div>
  </body>
  <script>
    const container = document.querySelector(".container");
    const cards = document.querySelectorAll(".card");
    container.onmousemove = function (e) {
      for (const card of cards) {
        const rect = card.getBoundingClientRect();
        const x = e.clientX - rect.left + rect.width / 8;
        const y = e.clientY - rect.top + rect.height / 8;
        console.log("rect", rect.left, rect.top, rect);
        console.log("e.clientX , e.clientY", e.clientX, e.clientY);
        console.log("x, y,", x, y);

        card.style.setProperty("--x", `${x}px`);
        card.style.setProperty("--y", `${y}px`);
      }
    };
  </script>
</html>
